package com.easyexcell.easyexcellexample.utils.esayexcell.handler;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.xssf.streaming.SXSSFSheet;

/**
 * 锁全局excell表
 *
 * @User c.c
 * @Since 2023/9/2
 * @Time 11:20
 * @Description
 */

public class LockSheetWriteHandler implements SheetWriteHandler {
  @Override
  public int order() {
    return 1000002;
  }

  @Override
  public void afterSheetCreate(
    WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
    // 设置保护密码
    writeSheetHolder.getSheet().protectSheet("123456");
    // 锁定单元格不可选中(防止别人直接复制内容到其他excel修改)
    ((SXSSFSheet) writeSheetHolder.getSheet()).lockSelectLockedCells(true);
  }

}
